package com.fit.pages;

import java.util.LinkedList;

import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.beans.EmployerBean;
import com.fit.interfaces.Borrow;
import com.fit.interfaces.Employer;
import com.fit.interfaces.Reservation;
import com.fit.interfaces.User;
import com.fit.service.Employers;

public class EntryEmployer {

	@SessionState
	private User user;
	
	private boolean userExists;

	public User getUser() {
		return user;
	}

	Object onActivate(){
		if(!userExists) return Login.class;
		return null;
	}
	@Persist
	@Property
	private Employer employer;
	
	@Inject
	private Employers employers;
	
	@SetupRender
	public void createObject(){
		employer = new EmployerBean();
		employer.setBorrow(new LinkedList<Borrow>());
		employer.setReservation(new LinkedList<Reservation>());
	}
	void onSuccess(){
		employers.save(employer);
	}
}
